package comoabejas

import comoabejas.Deal

class MainviewController {
	def dealService
	def clientService
	
    def index = {
    	//def dealList = Deal.list()
		def dealList = Deal.findAllByState("ACTIVE", [sort:"dateOfCreation",order:"desc"]);
		if(dealList ==null){
			throw new RuntimeException("no encontro un deal en estado active");
		}
		
    	Deal deal = dealList.get(0)
    	
		session.deal = deal
    	//[dealInstanceList: Deal.list(params), dealInstanceTotal: Deal.count(),client:cli]

		render(view: 'main_cambios', model:[dealInstance:deal,client:deal.getClient()] )
	}
	
	
	public void cargarDeal() {
		Deal deal = dealService.controlarFechaDeal()
		
		session.deal = deal
		
		render(view: 'main_cambios', model:[dealInstance:deal,client:deal.getClient()] )
	}
}
